﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace hamster
{
    abstract class WorldObject
    {
        public Matrix World
        {
            get
            {
                return localTransformations_ * Matrix.CreateScale(objectScale_) * Matrix.CreateWorld(new Vector3(position_, -1), -Vector3.UnitZ, upDir);
            }
        }
        float scale = Game1.RandomFloat;
        float randomness = Game1.RandomFloat;
        public Vector3 upDir = Vector3.UnitY;
        public Vector2 position_;
        public float rotation_;
        public float objectScale_ = 0.1f;
        public BoundingBox boundingBox_;
        public Matrix localTransformations_ = Matrix.Identity;
        public ObjectPlacer parent_;

        public Color debugColor_ = Color.Yellow;

        public WorldObject(Vector2 position, float rotation, ObjectPlacer parent)
        {
            position_ = position;
            rotation_ = rotation;
            parent_ = parent;
        }

        public void Initialise()
        {
        }

        public virtual bool Update(float dt, Player player)
        {
            upDir = Vector3.Transform(Vector3.Up, Matrix.CreateRotationZ(rotation_));
            localTransformations_ = Matrix.Identity;
            Vector3 halfSize = new Vector3(objectScale_);
            boundingBox_ = new BoundingBox(Vector3.Subtract(new Vector3(position_, -1), halfSize), Vector3.Add(new Vector3(position_, -1), halfSize));
            return false;
        }

        public virtual void Draw(GraphicsDevice device)
        {
            //Game1.DrawDebugSquare(localTransformations_ * Matrix.CreateScale(objectScale_) * Matrix.CreateWorld(new Vector3(position_, -1), -Vector3.UnitZ, upDir), debugColor_);
        }
    }
}
